import UIKit

class UTLaunchManager: NSObject {
    lazy var window: UIWindow? = {
        let window = UIWindow.init(frame: UIScreen.main.bounds)
        window.backgroundColor = .white
        window.windowLevel = .alert + 10000;
        window.isHidden = false
        return window
    }()
    
    
    override init() {
        super.init()
        addBootPageOrAdPage()
    }
    
    func addBootPageOrAdPage() {
        let status: Bool = UserDefaults.standard.bool(forKey: bootPageStatus)
        if !status {
            UserDefaults.standard.setValue(true, forKey: bootPageStatus)
            showbootPageViewController()
        }
    }
    
    func showbootPageViewController() {
        let bootPageVC = UTBootPageViewController()
        bootPageVC.delegate = self
        window?.rootViewController = bootPageVC
        window?.makeKeyAndVisible()
    }
    
}

extension UTLaunchManager: UTLaunchDelegate {
    func dismiss() {
        UIView.transition(with: window!,
                          duration: 0.5,
                          options: .transitionCrossDissolve,
                          animations: { [self] in
            self.window!.transform = CGAffineTransformMakeScale(1.5, 1.5);
            self.window!.alpha = 0;
          }, completion: { _ in
              self.window = nil;
          })
    }
}

